﻿using System;
using System.Collections.Generic;

namespace MinorAspNetCore.Server
{
    public interface IMinorFeatureCollection : IDictionary<Type, object> { }

    public class MinorFeatureCollection : Dictionary<Type, object>, IMinorFeatureCollection { }

    public static partial class Extensions
    {
        public static T Get<T>(this IMinorFeatureCollection features) => features.TryGetValue(typeof(T), out var value) ? (T)value : default(T);

        public static IMinorFeatureCollection Set<T>(this IMinorFeatureCollection features, T feature)
        {
            features[typeof(T)] = feature;
            return features;
        }
    }
}